package io.renren.modules.app.service.impl;

import com.zheok.testing.entity.ActivityEntity;
import com.zheok.testing.entity.BusinessEntity;
import com.zheok.testing.entity.ShopEntity;
import io.renren.common.utils.ShiroUtils;
import io.renren.modules.app.service.CaseService;
import io.renren.modules.app.service.ShopService;
import io.renren.modules.sys.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.zheok.testing.dao.CaseDao;
import com.zheok.testing.entity.CaseEntity;
import org.springframework.util.StringUtils;


@Service("caseService")
public class CaseServiceImpl extends ServiceImpl<CaseDao, CaseEntity> implements CaseService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<CaseEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        String username = userEntity.getUsername();
        if(!"admin".equals(username)){
            wrapper.lambda().eq(CaseEntity::getShopId,userEntity.getUserId());
        }
        if(!StringUtils.isEmpty(key)){
            wrapper.lambda().like(CaseEntity::getTitle,key);
        }
        IPage<CaseEntity> page = this.page(
                new Query<CaseEntity>().getPage(params),
              wrapper
        );

        return new PageUtils(page);
    }

    @Autowired
    ShopService shopService;
    @Override
    public void saveinfo(CaseEntity case1) {
        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        case1.setShopId(userEntity.getUserId());
        case1.setShopName(userEntity.getName());

        this.saveOrUpdate(case1);


    }

}